package com.itheima05;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDP04 {
    public static void main(String[] args) throws IOException {

        DatagramSocket datagramSocket = new DatagramSocket(10000);




            new Thread(()->{
                while (true) {
                byte[] bytes = new byte[1024];
                DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
                try {
                    datagramSocket.receive(datagramPacket);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                int length = datagramPacket.getLength();
                String s = new String(bytes, 0, length);
                System.out.println(s);

//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            }

        }).start();
    }
}
